package com.bc004346.travelus.Fragment;

import android.app.Activity;
import android.app.ListFragment;
import android.os.Bundle;
import android.widget.ArrayAdapter;

import com.bc004346.travelus.Model.Domain.Flight;
import com.bc004346.travelus.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Renats on 4/4/2014.
 * flat flight view
 */
public class FlightsFragment extends ListFragment {

    private Activity mActivity;

    public Activity getParentActivity() {
        if (mActivity == null)
            mActivity = getActivity();
        return mActivity;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    public void Populate(List<Flight> flights) {

        if (flights.size() > 0) {
            List<String> list = new ArrayList<String>();
            for (Flight flight : flights)
                list.add(flight.toString());
            ArrayAdapter<String> flightArrayAdapter =
                    new ArrayAdapter<String>(getParentActivity(),
                            R.layout.list_flight_simple, list);
            setListAdapter(flightArrayAdapter);
        } else {
            ArrayAdapter<String> flightArrayAdapter =
                    new ArrayAdapter<String>(getParentActivity(),
                            R.layout.list_flight_simple, new ArrayList<String>() {{
                        add(mActivity.getString(R.string.common_no_flights_found));
                    }}
                    );
            setListAdapter(flightArrayAdapter);
        }
    }
}
